package com.cdu.guoxinan.www.smartcom.controller;

import com.cdu.guoxinan.www.smartcom.domian.dto.VisitorQueryDTO;
import com.cdu.guoxinan.www.smartcom.domian.pojo.Visitor;
import com.cdu.guoxinan.www.smartcom.service.VisitorService;
import com.cdu.guoxinan.www.smartcom.unit.model.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/visitor")
@Api(tags = "访客控制器")
public class VisitorController {
    @Resource
    private VisitorService visitorService;
    @GetMapping("/queryPage")
    @ApiOperation(value = "分页查询访客信息")
    public R QueryPage(VisitorQueryDTO visitorQueryDTO){
        PageInfo<Visitor> pageInfo = visitorService.queryPage(visitorQueryDTO);
        return R.ok(pageInfo);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加访客信息")
    public R add(Visitor visitor){
        return visitorService.add(visitor)? R.ok("添加成功"):R.error("添加失败");
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新访客信息")
    public R update(Visitor visitor){
        return visitorService.update(visitor)? R.ok("修改成功"):R.error("修改失败");
    }
    @PostMapping("/delete")
    @ApiOperation(value = "删除访客信息")
    public R delete(Integer id){
        return visitorService.delete(id)? R.ok("删除成功"):R.error("删除失败");
    }
    @PostMapping("leave")
    @ApiOperation(value = "设置离开时间(当前时间)")
    public R leave(Integer id){
        return visitorService.leave(id)? R.ok("离开成功"):R.error("已离开");
    }

}
